package com.java.leetcode;

/**
 * @Author ynb
 * 66. 加一
 * @Date 2021/6/1 15:56
 * @Version 1
 */
public class LeetCode066 {
    public int[] plusOne(int[] digits) {
        int len = digits.length;
        for (int i=len-1;i>=0;i--){
            if (digits[i]!=9){
                digits[i]++;
                return digits;
            }
            digits[i] = 0;
        }
        int []  newDigits=new int[len+1];
        newDigits[0]=1;
        return  newDigits;
    }

    public static void main(String[] args) {
        LeetCode066 leetCode066 = new LeetCode066();
        int [] digits = {9,6,9};
        int[] ints = leetCode066.plusOne(digits);
        for(int  n:ints){
            System.out.println(n);
        }
    }
}
